home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / wb / Tripppin.lha / Tripppin / source / menu.c < prev    next >
C/C++ Source or Header  |  1991-01-10  |  9KB  |  419 lines

  1. /* this file is got the menu stuff for the game Trippin. */
  2.  
  3.  
  4. #include <intuition/intuition.h>
  5. #include "trip.h"
  6.  
  7.  
  8. #define MENWID 188
  9. #define SUBWID 154
  10.  
  11.  
  12. import struct Image olabel, blabel;
  13.  
  14. import void TellTurn(), Restart(), ShowBoard(), MakeAnts(), StartThinking(),
  15.         StopThinking(), DrawSquare(), LiftBob(), DropBob(),
  16.         TellTurn(), Ding();
  17.  
  18. import bool thinking, abort_think, lace, won, looprevent;
  19.  
  20. import short difficulty, sigdone, suggx, suggy, thite;
  21.  
  22. import piece bb, oo, *turn;
  23.  
  24. import struct Window *win;
  25.  
  26. import struct Task *child;
  27.  
  28.  
  29.  
  30. private struct IntuiText xquit = {
  31.     0, 1, JAM2, 4, 1, null, (ubyte *) "Quit the game", null
  32. };
  33.  
  34.  
  35. private struct MenuItem mlast = {
  36.     null, 0, (IMHITE << 1) + 64, MENWID, 10,
  37.     ITEMTEXT | ITEMENABLED | HIGHCOMP, 0L, (APTR) &xquit, null, 0, null, 0
  38. };
  39.  
  40.  
  41. private struct IntuiText xrestart = {
  42.     0, 1, JAM2, 4, 1, null, (ubyte *) "Start a new game", null
  43. };
  44.  
  45.  
  46. private struct MenuItem m7 = {
  47.     &mlast, 0, (IMHITE << 1) + 44, MENWID, 10,
  48.     ITEMTEXT | ITEMENABLED | HIGHCOMP, 0L, (APTR) &xrestart, null, 0, null, 0
  49. };
  50.  
  51.  
  52. private struct IntuiText xtakeback = {
  53.     0, 1, JAM2, 4, 1, null, (ubyte *) "Take back move", null
  54. };
  55.  
  56.  
  57. private struct MenuItem m6 = {
  58.     &m7, 0, (IMHITE << 1) + 34, MENWID, 10,
  59.     ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,
  60.     0L, (APTR) &xtakeback, null, 'T', null, 0
  61. };
  62.  
  63.  
  64. private struct IntuiText xsuggest = {
  65.     0, 1, JAM2, 4, 1, null, (ubyte *) "Suggest move", null
  66. };
  67.  
  68.  
  69. private struct MenuItem m5 = {
  70.     &m6, 0, (IMHITE << 1) + 24, MENWID, 10,
  71.     ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,
  72.     0L, (APTR) &xsuggest, null, 'S', null, 0
  73. };
  74.  
  75.  
  76. private struct IntuiText xprevent = {
  77.     0, 1, JAM2, 24, 1, null, (ubyte *) "Prevent loops", null
  78. };
  79.  
  80.  
  81. private struct MenuItem m4 = {
  82.     &m5, 0, (IMHITE << 1) + 14, MENWID, 10,
  83.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | CHECKED | MENUTOGGLE,
  84.     0L, (APTR) &xprevent, null, 0, null, 0
  85. };
  86.  
  87.  
  88. private struct IntuiText xd9 = {
  89.     0, 1, JAM2, 24, 1, null, (ubyte *) "9  ( zzz...)", null
  90. };
  91.  
  92.  
  93. private struct IntuiText xd8 = {
  94.     0, 1, JAM2, 24, 1, null, (ubyte *) "8  (savage)", null
  95. };
  96.  
  97.  
  98. private struct IntuiText xd7 = {
  99.     0, 1, JAM2, 24, 1, null, (ubyte *) "7  (brutal)", null
  100. };
  101.  
  102.  
  103. private struct IntuiText xd6 = {
  104.     0, 1, JAM2, 24, 1, null, (ubyte *) "6  (mean)", null
  105. };
  106.  
  107.  
  108. private struct IntuiText xd5 = {
  109.     0, 1, JAM2, 24, 1, null, (ubyte *) "5  (tough)", null
  110. };
  111.  
  112.  
  113. private struct IntuiText xd4 = {
  114.     0, 1, JAM2, 24, 1, null, (ubyte *) "4  (slick)", null
  115. };
  116.  
  117.  
  118. private struct IntuiText xd3 = {
  119.     0, 1, JAM2, 24, 1, null, (ubyte *) "3  (wary)", null
  120. };
  121.  
  122.  
  123. private struct IntuiText xd2 = {
  124.     0, 1, JAM2, 24, 1, null, (ubyte *) "2  (sloppy)", null
  125. };
  126.  
  127.  
  128. private struct IntuiText xd1 = {
  129.     0, 1, JAM2, 24, 1, null, (ubyte *) "1  (duuh...)", null
  130. };
  131.  
  132.  
  133. private struct IntuiText xdifficulty = {
  134.     0, 1, JAM2, 4, 1, null, (ubyte *) "Difficulty level:", null
  135. };
  136.  
  137.  
  138. private struct MenuItem m3i = {
  139.     null, MENWID - 26, 40, SUBWID, 10,
  140.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  141.     0xfffffeffL, (APTR) &xd9, null, 0, null, 0
  142. };
  143.  
  144.  
  145. private struct MenuItem m3h = {
  146.     &m3i, MENWID - 26, 30, SUBWID, 10,
  147.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  148.     0xffffff7fL, (APTR) &xd8, null, 0, null, 0
  149. };
  150.  
  151.  
  152. private struct MenuItem m3g = {
  153.     &m3h, MENWID - 26, 20, SUBWID, 10,
  154.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  155.     0xffffffbfL, (APTR) &xd7, null, 0, null, 0
  156. };
  157.  
  158.  
  159. private struct MenuItem m3f = {
  160.     &m3g, MENWID - 26, 10, SUBWID, 10,
  161.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  162.     0xffffffdfL, (APTR) &xd6, null, 0, null, 0
  163. };
  164.  
  165.  
  166. private struct MenuItem m3e = {
  167.     &m3f, MENWID - 26, 0, SUBWID, 10,
  168.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  169.     0xffffffefL, (APTR) &xd5, null, 0, null, 0
  170. };
  171.  
  172.  
  173. private struct MenuItem m3d = {
  174.     &m3e, MENWID - 26, -10, SUBWID, 10,
  175.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  176.     0xfffffff7L, (APTR) &xd4, null, 0, null, 0
  177. };
  178.  
  179.  
  180. private struct MenuItem m3c = {
  181.     &m3d, MENWID - 26, -20, SUBWID, 10,
  182.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | CHECKED,
  183.     0xfffffffbL, (APTR) &xd3, null, 0, null, 0
  184. };
  185.  
  186.  
  187. private struct MenuItem m3b = {
  188.     &m3c, MENWID - 26, -30, SUBWID, 10,
  189.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  190.     0xfffffffdL, (APTR) &xd2, null, 0, null, 0
  191. };
  192.  
  193.  
  194. private struct MenuItem m3a = {
  195.     &m3b, MENWID - 26, -40, SUBWID, 10,
  196.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  197.     0xfffffffeL, (APTR) &xd1, null, 0, null, 0
  198. };
  199.  
  200.  
  201. private struct MenuItem m3 = {
  202.     &m4, 0, (IMHITE << 1) + 4, MENWID, 10, ITEMTEXT | ITEMENABLED | HIGHNONE,
  203.     0L, (APTR) &xdifficulty, null, 0, &m3a, 0
  204. };
  205.  
  206.  
  207. private struct IntuiText xcomputer = {
  208.     0, 1, JAM2, 24, 1, null, (ubyte *) "Computer", null
  209. };
  210.  
  211.  
  212. private struct IntuiText xhuman = {
  213.     0, 1, JAM2, 24, 1, null, (ubyte *) "Human", null
  214. };
  215.  
  216.  
  217. private struct IntuiText xplayedby = {
  218.     0, 1, JAM2, 38, 3, null, (ubyte *) "is played by:", null
  219. };
  220.  
  221.  
  222. private struct MenuItem m2b = {
  223.     null, MENWID - 26, 10, SUBWID, 10,
  224.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | CHECKED, bit(0),
  225.     (APTR) &xcomputer, null, 0, null, 0
  226. };
  227.  
  228.  
  229. private struct MenuItem m2a = {
  230.     &m2b, MENWID - 26, 0, SUBWID, 10,
  231.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT, bit(1),
  232.     (APTR) &xhuman, null, 0, null, 0
  233. };
  234.  
  235.  
  236. private struct MenuItem m1b = {
  237.     null, MENWID - 26, 10, SUBWID, 10,
  238.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT, bit(0),
  239.     (APTR) &xcomputer, null, 0, null, 0
  240. };
  241.  
  242.  
  243. private struct MenuItem m1a = {
  244.     &m1b, MENWID - 26, 0, SUBWID, 10,
  245.     ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | CHECKED, bit(1),
  246.     (APTR) &xhuman, null, 0, null, 0
  247. };
  248.  
  249.  
  250. private struct MenuItem m2i = {
  251.     &m3, 6, IMHITE + 3, 32, IMHITE, ITEMENABLED | HIGHNONE, 0L,
  252.     (APTR) &blabel, null, 0, null, 0
  253. };
  254.  
  255.  
  256. private struct MenuItem m2 = {
  257.     &m2i, 0, IMHITE + 2, MENWID, IMHITE + 2, ITEMTEXT | ITEMENABLED | HIGHNONE,
  258.     0L, (APTR) &xplayedby, null, 0, &m2a, 0
  259. };
  260.  
  261.  
  262. private struct MenuItem m1i = {
  263.     &m2, 6, 1, 32, IMHITE, ITEMENABLED | HIGHNONE, 0L,
  264.     (APTR) &olabel, null, 0, null, 0
  265. };
  266.  
  267.  
  268. private struct MenuItem m1 = {
  269.     &m1i, 0, 0, MENWID, IMHITE + 2, ITEMTEXT | ITEMENABLED | HIGHNONE, 0L,
  270.     (APTR) &xplayedby, null, 0, &m1a, 0
  271. };
  272.  
  273.  
  274.  
  275. PUBLIC struct Menu manyou = {
  276.     null, 210, 0, MENWID, 10, MENUENABLED, "Tripppin out!", &m1, 0, 0, 0, 0
  277. };
  278.  
  279. /* ------------------ JEEZ!  All that for just ONE menu?! ------------ */
  280.  
  281.  
  282.  
  283. private void Spread(m, h) struct MenuItem *m; short h;
  284. {
  285.     short t;
  286.     for (t = 0; m; m = m->NextItem) {
  287.     m->TopEdge += t;
  288.     m->Height = thite + 1;
  289.     t += h;
  290.     }
  291. }
  292.  
  293.  
  294.  
  295. void ShoveMenus()        /* compensate for lace and/or tall font */
  296. {
  297.     struct MenuItem *mi;
  298.     short t = (IMHITE << 2) + 8, h = thite - 9;
  299.  
  300.     if (lace) {
  301.     m1.Height = m2.Height = m2.TopEdge = (IMHITE << 1) + 4;
  302.     xplayedby.TopEdge = (IMHITE >> 1) + 3;
  303.     m2i.TopEdge = (IMHITE << 1) + 5;
  304.     m1i.Height = m2i.Height = IMHITE << 2;
  305.     for (mi = &m3; mi; mi = mi->NextItem) {
  306.         mi->TopEdge = t;
  307.         t += 10;
  308.     }
  309.     mlast.TopEdge += 10;
  310.     }
  311.     if (h > 0) {
  312.     Spread(&m3, h);            /* main items below imaged ones */
  313.     Spread(&m3a, h);        /* difficulty subitems */
  314.     manyou.Height = thite + 1;
  315.     Spread(&m1a, h);
  316.     Spread(&m2a, h);
  317.     }
  318.     /* this function assumes that thite < IMHITE + 2 */
  319. }
  320.  
  321.  
  322.  
  323. private void Suck(who) piece *who;
  324. {
  325.     history *h = who->hist;
  326.     if (!h->count)
  327.     return;
  328.     turn = turn->other;
  329.     LiftBob(who);
  330.     DrawSquare(who->x, who->y);
  331.     who->x = h->hx[h->top];
  332.     who->y = h->hy[h->top];
  333.     if (h->madegoal[h->top]) {
  334.     --who->reached;
  335.     SetGoal(who);
  336.     }
  337.     if (!h->top)
  338.     h->top = HISTORY - 1;
  339.     else --h->top;
  340.     --h->count;
  341.     DropBob(who);
  342. }
  343.  
  344.  
  345.  
  346. private void TakeBack()
  347. {
  348.     piece *oldturn = turn;
  349.  
  350.     if ((oo.machine && bb.machine) || !turn->other->hist->count) {
  351.     Ding();
  352.     return;
  353.     }
  354.     StopThinking();
  355.     KillAnts(); 
  356.     won = false;
  357.     Suck(turn->other);
  358.     if (oldturn->other->machine)
  359.     Suck(oldturn);
  360.     Allow(turn->other, turn);
  361.     TellTurn();
  362.     StartThinking();
  363. }
  364.  
  365.  
  366.  
  367. bool DoMenu(c) short c;
  368. {
  369.     struct MenuItem *eye;
  370.     short i;
  371.  
  372.     switch (c) {
  373.     case 0:        /* orange player */
  374.         if ((oo.machine ? m1a.Flags : m1b.Flags) & CHECKED) {
  375.         oo.machine = !oo.machine;
  376.         if (turn == &oo) {
  377.             KillAnts();
  378.             StartThinking();
  379.             TellTurn();
  380.         }
  381.         }
  382.         break;
  383.     case 2:        /* blue player */
  384.         if ((bb.machine ? m2a.Flags : m2b.Flags) & CHECKED) {
  385.         bb.machine = !bb.machine;
  386.         if (turn == &bb) {
  387.             KillAnts();
  388.             StartThinking();
  389.             TellTurn();
  390.         }
  391.         }
  392.         break;
  393.     case 4:        /* difficulty level */
  394.         for (i = 1, eye = &m3a; eye; eye = eye->NextItem, i++)
  395.         if (eye->Flags & CHECKED) {
  396.             difficulty = i;
  397.             break;
  398.         }
  399.         /* do *NOT* trust SUBITEM to be same as the one now checked! */
  400.         break;
  401.     case 6:        /* suggest a move */
  402.         if (suggx >= 0)
  403.         MakeAnts(suggx, suggy);
  404.         break;
  405.     case 7:        /* take back a move */
  406.         TakeBack();
  407.         break;
  408.     case 8:        /* restart the game */
  409.         Restart();
  410.         ShowBoard();
  411.         break;
  412.     case 9:        /* quit the game */
  413.         abort_think = true;
  414.         return true;
  415.     }
  416.     looprevent = !!(m4.Flags & CHECKED);
  417.     return false;
  418. }
  419.